﻿using HcyWebAPI.Models;
using Microsoft.AspNetCore.Mvc;
using static HcyWebAPI.Controllers.Params.AccountParams;

namespace HcyWebAPI.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class DeptController : ControllerBase
    {
        private readonly MyDbContext _contextDept = new MyDbContext();

        //[HttpGet]
        //[Route("get1")]
        //public string get1() {
        //    return "get1";
        //}

        [HttpPost]
        [Route("list")]
        public Models.ResultMsg GetDeptList(AccountListParams? @params)
        {
            Models.ResultMsg resultMsg = new Models.ResultMsg();
            Models.ResultDataInfo resultDataInfo = new Models.ResultDataInfo();
            Func<Models.Dept, bool> whereLam = (p => true);
            //if (@params.username != null && @params.username != "")
            //{
            //    whereLam = p => p.Username.Contains(@params.username);
            //}
            //if (@params.deptId != 0)
            //{
            //    whereLam = (p => p.DeptId == @params.deptId);
            //}
            //var temp =new List<String>();
            //var count = 10;

            var temp = _contextDept.Dept.Where(whereLam)
                                     .OrderBy(p => p.Id)
                                     .Skip(@params.pageSize * (@params.pageIndex - 1))  //跳过多少
                                     .Take(@params.pageSize)                            //取多少
                                     .ToList();
            var count = _contextDept.Dept.Count(whereLam);
            //最后转为集合

            resultDataInfo.data = temp;
            resultDataInfo.total = count;
            resultMsg.data = resultDataInfo;
            return resultMsg;
        }

    }
}
